package offer;

public class erweishuzu04 {


    class Solution {
        public boolean findNumberIn2DArray(int[][] matrix, int target) {
            for (int i = 0; i < matrix.length - 1; i++) {
                if (binary(matrix[i], 0, matrix[0].length, target))
                    return true;
            }
            return false;
        }

        private boolean binary(int[] arr, int left, int right, int target) {
            if (left > right) {
                return false;
            }
            int mid = right - (right - left) / 2;
            if (arr[mid] == target) {
                return true;
            } else if (arr[mid] > target) {
                return binary(arr, left, mid - 1, target);
            } else {
                return binary(arr, mid + 1, right, target);
            }
        }
    }
}
